package cn.ibizlab.odoo.core.odoo_mail.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Imail_activity_mixin;
import cn.ibizlab.odoo.core.odoo_mail.domain.Mail_activity_mixin;
import cn.ibizlab.odoo.core.odoo_mail.filter.Mail_activity_mixinSearchContext;
import cn.ibizlab.odoo.core.odoo_mail.service.IMail_activity_mixinService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[活动Mixin] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Mail_activity_mixinServiceImpl implements IMail_activity_mixinService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Imail_activity_mixinClientService mail_activity_mixinClientService;

    @Override
    public Mail_activity_mixin get(Integer id) {
        Imail_activity_mixin clientModel = mail_activity_mixinClientService.createModel();
        clientModel.setId(id);
        mail_activity_mixinClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Mail_activity_mixin get(Mail_activity_mixin mail_activity_mixin) {
        Mail_activity_mixin retmail_activity_mixin = this.get(mail_activity_mixin.getId()) ;
    	BeanCopier copier=BeanCopier.create(retmail_activity_mixin.getClass(), mail_activity_mixin.getClass(), false);
        copier.copy(retmail_activity_mixin, mail_activity_mixin, null);
        return mail_activity_mixin ;
    }

    @Override
    public boolean update(Mail_activity_mixin mail_activity_mixin) {
        boolean bOk = false ;
        Imail_activity_mixin clientModel = this.convert2Model(mail_activity_mixin,null);
        mail_activity_mixinClientService.update(clientModel) ;
        this.convert2Domain(clientModel,mail_activity_mixin) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean create(Mail_activity_mixin mail_activity_mixin) {
        boolean bOk = false ;
        Imail_activity_mixin clientModel = this.convert2Model(mail_activity_mixin,null);
        mail_activity_mixinClientService.create(clientModel) ;
        this.convert2Domain(clientModel,mail_activity_mixin);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //mail_activity_mixinClientService.removeBatch(mail_activity_mixins) ;

    }

    @Override
    public void createBatch(List<Mail_activity_mixin> mail_activity_mixins, int batchSize) {

                        //mail_activity_mixinClientService.createBatch(mail_activity_mixins,batchSize) ;

    }

    @Override
    public void updateBatch(List<Mail_activity_mixin> mail_activity_mixins, int batchSize) {

        //mail_activity_mixinClientService.updateBatch(mail_activity_mixins,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Imail_activity_mixin clientModel = mail_activity_mixinClientService.createModel();
        clientModel.setId(id);
        mail_activity_mixinClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Mail_activity_mixin> searchDefault(Mail_activity_mixinSearchContext context) {
        List<Mail_activity_mixin> list = new ArrayList<Mail_activity_mixin>();
        Page<cn.ibizlab.odoo.core.client.model.Imail_activity_mixin> clientModelList = mail_activity_mixinClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imail_activity_mixin clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Mail_activity_mixin>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Imail_activity_mixin convert2Model(Mail_activity_mixin domain , Imail_activity_mixin model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = mail_activity_mixinClientService.createModel() ;
        }

         if(domain.getActivity_summaryDirtyFlag())
            model.setActivity_summary(domain.getActivity_summary());
         if(domain.getActivity_date_deadlineDirtyFlag())
            model.setActivity_date_deadline(domain.getActivity_date_deadline());
         if(domain.getActivity_stateDirtyFlag())
            model.setActivity_state(domain.getActivity_state());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getActivity_type_idDirtyFlag())
            model.setActivity_type_id(domain.getActivity_type_id());
         if(domain.getActivity_user_idDirtyFlag())
            model.setActivity_user_id(domain.getActivity_user_id());
         if(domain.getActivity_idsDirtyFlag())
            model.setActivity_ids(domain.getActivity_ids());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
        return model ;
    }

    public Mail_activity_mixin convert2Domain( Imail_activity_mixin model ,Mail_activity_mixin domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Mail_activity_mixin();
        }

        if(model.getActivity_summaryDirtyFlag())
            domain.setActivity_summary(model.getActivity_summary());
        if(model.getActivity_date_deadlineDirtyFlag())
            domain.setActivity_date_deadline(model.getActivity_date_deadline());
        if(model.getActivity_stateDirtyFlag())
            domain.setActivity_state(model.getActivity_state());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getActivity_type_idDirtyFlag())
            domain.setActivity_type_id(model.getActivity_type_id());
        if(model.getActivity_user_idDirtyFlag())
            domain.setActivity_user_id(model.getActivity_user_id());
        if(model.getActivity_idsDirtyFlag())
            domain.setActivity_ids(model.getActivity_ids());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        return domain ;
    }


}
